
"""
@名称：练习
@作者：Fida1214
@日期：2025/4/9
"""

"""
第一题，超级英雄战斗模拟
"""

import random

class Superhero:
    def __init__(self,name,power,health):
        self.name = name
        self.power = power
        self.health = health

    def attack(self,otherhero):
        damage = random.randint(1,self.power)
        otherhero.health -= damage
        print(f"{self.name} 攻击了 {otherhero.name}，造成了{damage} 点伤害！")
        if otherhero.health <= 0:
            print(f"你击败了{otherhero.name} ！")
        else:
            print(f"{otherhero.name} 还剩下 {otherhero.health} 点生命值。")

superman = Superhero("超人", 50, 200)
batman = Superhero("蝙蝠侠", 30, 150)

print("战斗开始！")
while superman.health > 0 and batman.health > 0:
    if random.choice([True, False]):
        superman.attack(batman)
    else:
        batman.attack(superman)
